﻿// Decompiled with JetBrains decompiler
// Type: LayersParser.Extensions.StringExtension
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.Linq;


namespace LayersParser.Extensions;

public static class StringExtension
{
  public static List<string> SeparateItems(
    this string line,
    List<string> parametersname,
    List<string> dynamicParamsname)
  {
    List<string> cutline1 = new List<string>();
    List<string> cutline2 = new List<string>();
    string[] strArray1;
    if (parametersname.Count > 0)
      strArray1 = line.Split(parametersname.CreateSplitting(), StringSplitOptions.None);
    else
      strArray1 = new string[1]{ line };
    List<string> stringList1 = new List<string>();
    string[] strArray2;
    if (dynamicParamsname.Count > 0)
    {
      foreach (string str1 in strArray1)
      {
        foreach (string str2 in str1.Split(dynamicParamsname.CreateSplitting(), StringSplitOptions.None).RemoveVoid())
          stringList1.Add(str2);
      }
      strArray2 = stringList1.ToArray();
    }
    else
      strArray2 = strArray1;
    foreach (string str in ((IEnumerable<string>) line.Split(((IEnumerable<string>) strArray2).ToList<string>().CreateSplitting(), StringSplitOptions.None)).ToList<string>())
    {
      if (parametersname.Contains(str))
        cutline1.Add(str);
      if (dynamicParamsname.Contains(str))
        cutline2.Add(str);
    }
    List<string> stringList2 = cutline1.RemoveVoid();
    List<string> stringList3 = cutline2.RemoveVoid();
    List<string> stringList4 = new List<string>();
    if (stringList2.Count != 0 || strArray2.Length != 0 || stringList3.Count != 0)
    {
      string[] source = strArray2.RemoveVoid();
      int startIndex = 0;
      while (source.Length != 0 || stringList2.Count > 0 || stringList3.Count > 0)
      {
        int num1 = -1;
        int num2 = -1;
        int num3 = -1;
        if (source.Length != 0)
          num1 = line.IndexOf(source[0], startIndex);
        if (stringList2.Count != 0)
          num2 = line.IndexOf(stringList2[0], startIndex);
        if (stringList3.Count != 0)
          num3 = line.IndexOf(stringList3[0], startIndex);
        if (StringExtension.IsMinimum(num1, num2, num3))
        {
          startIndex = num1 + source[0].Length;
          stringList4.Add(source[0]);
          List<string> list = ((IEnumerable<string>) source).ToList<string>();
          list.RemoveAt(0);
          source = list.ToArray();
        }
        else if (StringExtension.IsMinimum(num2, num1, num3))
        {
          startIndex = num2 + stringList2[0].Length;
          stringList4.Add(stringList2[0]);
          stringList2.RemoveAt(0);
        }
        else if (StringExtension.IsMinimum(num3, num2, num1))
        {
          startIndex = num3 + stringList3[0].Length;
          stringList4.Add(stringList3[0]);
          stringList3.RemoveAt(0);
        }
      }
      return stringList4;
    }
    return ((IEnumerable<string>) new string[1]{ line }).ToList<string>();
  }

  public static string[] RemoveVoid(this string[] cutline)
  {
    int index = 0;
    while (index < cutline.Length)
    {
      if (cutline[index] == "")
      {
        List<string> list = ((IEnumerable<string>) cutline).ToList<string>();
        list.RemoveAt(index);
        cutline = list.ToArray();
      }
      else
        ++index;
    }
    return cutline;
  }

  public static List<string> RemoveVoid(this List<string> cutline)
  {
    int index = 0;
    while (index < cutline.Count)
    {
      if (cutline[index] == "")
        cutline.RemoveAt(index);
      else
        ++index;
    }
    return cutline;
  }

  public static bool IsMinimum(int toProove, int toCompare1, int toCompare2)
  {
    if (toProove == -1)
      return false;
    if (toCompare1 == -1 && toCompare2 != -1)
      return toProove < toCompare2;
    if (toCompare2 == -1 && toCompare1 != -1)
      return toProove < toCompare1;
    if (toCompare1 == -1 || toCompare2 == -1)
      return true;
    return toProove < toCompare1 && toProove < toCompare2;
  }

  public static bool IsJustWhiteSpace(this string line)
  {
    foreach (char c in line.ToCharArray())
    {
      if (char.IsLetter(c) || char.IsDigit(c))
        return false;
    }
    return true;
  }

  public static string[] CreateSplitting(this List<string> strings)
  {
    List<string> stringList = new List<string>();
    strings = strings.RemoveDuplicates();
    foreach (string str1 in strings)
    {
      string[] strArray = str1.Split(stringList.ToArray(), StringSplitOptions.RemoveEmptyEntries);
      if (strArray.Length == 1 || stringList.Count == 0)
      {
        stringList.Add(str1);
      }
      else
      {
        foreach (string str2 in strArray)
          stringList.Add(str2);
      }
    }
    return stringList.ToArray().RemoveVoid();
  }

  public static List<string> RemoveDuplicates(this List<string> strings)
  {
    List<string> stringList = new List<string>();
    foreach (string str in strings)
    {
      if (!stringList.Contains(str))
        stringList.Add(str);
    }
    return stringList;
  }
}
